1. Field of Invention
The present invention relates generally to synchronizing threads in an object-based environment. More particularly, the present invention relates enabling inconsistent threads to become consistent when a requesting thread requests a consistent state.
2. Description of the Related Art
Within an object-based environment, threads are often used to satisfy requests for services. A thread may be thought of as a “sketch pad” of storage resources, and is essentially a single sequential flow of control within a computer program. In general, a thread, or a “thread of control,” is a sequence of central processing unit (CPU) instructions or programming language statements that may be independently executed. Each thread in a multi-threaded environment has its own execution stack on which method activations reside. As will be appreciated by those skilled in the art, when a method is activated with respect to a thread, an activation is “pushed” on the execution stack of the thread. When the method returns, or is deactivated, the activation is “popped” from the execution stack. Since an activation of one method may activate another method, an execution stack operates in a first-in-last-out manner.
While maintaining multiple threads, a computing system may need to perform global operations which require synchronization, or control of all threads or a set of threads at a given time. One example of such a global operation is garbage collection. As will be appreciated by those skilled in the art, garbage collection is a method which allows memory storage associated with objects which are no longer alive to be automatically reclaimed.
Garbage collection generally occurs in two phases. A first phase typically involves identifying objects which are no longer needed or no longer in use, while a second phase renders the storage associated with the unneeded objects available for reallocation. An object in a program is needed, or alive, at a given time if a program may access the object in the future. When an object is such that it will not be accessed in the future, the object is considered to be unneeded or dead. Garbage collection algorithms, or “garbage collectors,” typically consider an object to be dead substantially only when a program has abandoned all pointers to the object, making future access to the object impossible.
All locations of objects and all locations of reference pointers typically need to be known to perform a global operation such as a garbage collection. In a multi-threaded environment, a “stop” instruction is typically sent to all threads prior to performing a global operation. Once a stop instruction is sent to all threads, it is generally determined whether each thread is in a “safe” region or an “unsafe” region. A safe region is often considered to be a region of code through which a thread is processing, and in which pointers are not being manipulated. An unsafe region is often considered to be a region of the code through which a thread is processing, and in which pointers may be manipulated. Conventionally, all threads are typically suspended in order to evaluate each thread and to determine the disposition of each individual thread, i.e., to determine whether each thread is in a safe region or an unsafe region. When a thread is determined to be in an unsafe region, the thread is typically allowed to resume its operation, and is stopped at a subsequent point in time in order to attempt to suspend the thread at a safe region.
While thread suspension may be effective in some computing systems, typically, the more concurrent threads that are in use at any given time, the slower thread suspension progresses. Accordingly, suspension processes are very expensive to perform on many of computing systems which support many concurrent threads, due, for instance, to the fact that the speed associated with a system may be significantly compromised.
Therefore, what is desired is a relatively inexpensive method and apparatus for enabling a global safe-point operation to be performed. Specifically, what is needed is a method and an apparatus for enabling safe-point operations to be performed without the need to suspend all threads in a multi-threaded environment.